package com.ruirui.demo;

import reactor.core.publisher.Flux;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

/**
 * 自定义线程调度
 */
public class FluxThread {
    public static void main(String[] args) throws Exception{

        //调度器 也就是线程池
        Scheduler immediate = Schedulers.immediate();// 当前线程池

        Scheduler single = Schedulers.single();// 单线程
        Scheduler bound = Schedulers.boundedElastic();//有界 弹性调度 线程池
        Scheduler parallel = Schedulers.parallel(); //并发池
        Flux.range(1, 5)
                .publishOn(bound)
                .map(value->value+"22")
                .log()
                .publishOn(single)
                .log()
                .subscribeOn(parallel)
                .subscribe(System.out::println);
      System.in.read();
        /**
         * | 操作符           | 控制谁在哪个线程上运行                  |
         * | ------------- | ---------------------------- |
         * | `subscribeOn` | 控制 **整个 Flux 流从源头开始**在哪个线程运行 |
         * | `publishOn`   | 控制 **当前位置之后**的操作在哪个线程运行      |
         */
    }
}
